﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DRHotel_v1.Classes.DBManagers;
using DRHotel_v1.RoomAvaAndBooking;

namespace DRHotel_v1.RoomAvaAndBooking
{
    public partial class CustomerRecordFrm : Form
    {
        public ArrayList cusList;
        public string selectedCusIC;
        private string IC;
        private string ICType;
        private string firstName;
        private string lastName;
        private string cusType;
        public string staffID;

        public CustomerRecordFrm()
        {
            InitializeComponent();
        }

        private void CustomerRecordFrm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dRHotelMngSysDataSet2.Customer' table. You can move, or remove it, as needed.
            this.customerTableAdapter.Fill(this.dRHotelMngSysDataSet2.Customer);
            cbbCusType.SelectedIndex = 0;
            cbbICType.SelectedIndex = 0;

        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewTextBoxCell cellCusIC = (DataGridViewTextBoxCell)
                dataGridView1.Rows[e.RowIndex].Cells[0];
            DataGridViewTextBoxCell cellICType = (DataGridViewTextBoxCell)
                dataGridView1.Rows[e.RowIndex].Cells[1];
            DataGridViewTextBoxCell cellFirstName = (DataGridViewTextBoxCell)
                dataGridView1.Rows[e.RowIndex].Cells[2];
            DataGridViewTextBoxCell cellLastName = (DataGridViewTextBoxCell)
                dataGridView1.Rows[e.RowIndex].Cells[3];
            DataGridViewTextBoxCell cellCusType = (DataGridViewTextBoxCell)
                dataGridView1.Rows[e.RowIndex].Cells[11];

            selectedCusIC = cellCusIC.Value.ToString();
            tbxIC.Text = selectedCusIC;
            //selectedCusIC = Convert.ToString(cellCusIC.Value);
            cbbICType.Text = cellICType.Value.ToString();
            //selectedRoomID = Convert.ToInt16(cellRoomID.Value);
            tbxFirstName.Text = cellFirstName.Value.ToString();
            //resStatus = Convert.ToString(cellResStatus.Value);
            tbxLastName.Text = cellLastName.Value.ToString();
            cbbCusType.Text = cellCusType.Value.ToString();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            IC = tbxIC.Text;
            ICType = cbbICType.Text;
            firstName = tbxFirstName.Text;
            lastName = tbxLastName.Text;
            cusType = cbbCusType.Text;
            ArrayList searchList = RoomAvaAndBookingDBManager.SearchCustomer(IC, ICType, firstName, lastName, cusType);
            dataGridView1.DataSource = searchList;
        }

        private void btnGetAll_Click(object sender, EventArgs e)
        {
            ArrayList searchList = RoomAvaAndBookingDBManager.GetAllCustomer();
            dataGridView1.DataSource = searchList;

        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (tbxIC.TextLength == 0)
            {
                MessageBox.Show("Please select a record to continue!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            CustomerUpdateFrm frm = new CustomerUpdateFrm();
            frm.staffID = staffID;
            frm.cusIC = selectedCusIC;
            frm.Show();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            tbxIC.Clear();
            tbxFirstName.Clear();
            tbxLastName.Clear();
            cbbCusType.SelectedIndex = 0;
            cbbICType.SelectedIndex = 0;
        }

        private void tbnCreate_Click(object sender, EventArgs e)
        {
            CustomerCreateFrm frm = new CustomerCreateFrm();
            frm.Show();
        }
    }
}
